<?php
declare(strict_types=1);

use Mpdf\Mpdf;
use Mpdf\MpdfException;
use Mpdf\Output\Destination;


class c_pdf extends Control
{
    //参考网址
    protected string $url = 'https://cloud.tencent.com/developer/article/2434266';
	public function index()
	{
        $mpdf = new Mpdf();
        try {
            $mpdf->WriteHTML('<h1>Hello world!</h1>');
            $mpdf->Output();
        } catch (MpdfException $e) {
            echo $e->getMessage();
        }
	}

    public function example()
    {
        $html = "
        <!DOCTYPE html>
        <html lang='sen'>
        <head>
            <meta charset='UTF-8'>
            <title>森小开</title>
        </head>
        <body>
        <h1 style='text-align: center'>森小开</h1>
        <table cellspacing='0' border='1' width=100% style='text-align: center'>
            <tr>
                <th>序号</th>
                <th>名称</th>
                <th>项目地址</th>
            </tr>
            <tr>
                <td>1</td>
                <td>Sen.php</td>
                <td>http://senyimiao.com/?c=pdf&m=example</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Validate 验证器插件</td>
                <td>https://www.workerman.net/plugin/7</td>
            </tr>
            <tr>
                <td>3</td>
                <td>Casbin 权限插件（Casbin官方）</td>
                <td>https://www.workerman.net/plugin/8</td>
            </tr>
        </table>
        </body>
        </html>";

        try {
            $mpdf = new Mpdf([
                //设置中文字体
                'autoScriptToLang' => true,
                'autoLangToFont'   => true,
                'useSubstitutions' => true,
                //设置格式
                'mode' => 'UTF-8',
                'format' => 'A4',
                'default_font_size' => 16,
                'default_font' => '宋体'
            ]);
            // 加载HTML文件
            $mpdf->WriteHTML($html);
            // 输出PDF文件
//            $mpdf->Output('./pdf01.pdf', Destination::FILE);
            $mpdf->Output();
        } catch (MpdfException $e) {
            echo $e->getMessage();
        }

    }

}